/**
 * Test.Case class for running funit tests. 
 * Enables to inject multiple test environments by theirs name. 
 */
Core.Test.Environment = function(fixture, runner) {
	fixture = fixture || {};

	this.fixtureAfter = fixture.tearDown || fixture.after || function() {};
	this.fixtureBefore = fixture.setUp || fixture.before || function() {};
	
	var envs = this.envs = [];
	Array.each(fixture.envs, function(name) {
		envs.push(runner.getEnvironment(name));
	});
	
	delete fixture.envs;
	delete fixture.setUp;
	delete fixture.after;
	delete fixture.before;
	delete fixture.tearDown;
	
	Core.Test.Environment.superclass.constructor.call(this, fixture);
};

Env.extend(Core.Test.Environment, Test.Case, {
	
	/**
	 * Prepares environment before each test.
	 * Runs each of the defined environments before() and then the fixture specific before().
	 */
	setUp: function() {
		Array.each(this.envs, function(env) {
			if(env.before) { env.before(); }
		})
		this.fixtureBefore();
	},
	
	/**
	 * Cleans environment after each test.
	 * Runs the fixture specific after() and then each of the defined environments after().
	 */
	tearDown: function() {
		this.fixtureAfter();
		Array.each(this.envs, function(env) {
			if(env.after) { env.after(); }
		});
	}	
});